<template>
  <div>
    <DockerTitle titleText="检查申请"></DockerTitle>
    <el-table style="margin-top: 20px" ref="wytable" :data="tableData">
      <el-table-column type="selection" width="55" />
      <el-table-column label="检查编码" prop="techCode"></el-table-column>
      <el-table-column label="检查名称" prop="techName"></el-table-column>
      <el-table-column label="检查规格" prop="techFormat"></el-table-column>
      <el-table-column label="单价" prop="techPrice"></el-table-column>
      <el-table-column label="费用分类" prop="priceType"></el-table-column>
      <el-table-column>
        <template #header>
          <el-button size="small" type="primary" @click="checkDialog.show = true">添加</el-button>
          <el-button size="small" type="danger" @click="delCheck">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-form :model="wyform" label-width="100px">
      <el-form-item label="目的要求">
        <el-input type="textarea" :rows="3" v-model="wyform.checkInfo" placeholder="请输入目的要求"></el-input>
      </el-form-item>
      <el-form-item label="检查部位">
        <el-input type="textarea" :rows="3" v-model="wyform.checkPosition" placeholder="请输入检查部位"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" :rows="3" v-model="wyform.checkRemark" placeholder="请输入现病治疗情况"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save" >保存</el-button>
      </el-form-item>
    </el-form>
    <el-dialog
        v-model="checkDialog.show"
        title="检查项目列表"
        width="800px">
      <CheckList v-model:tableData="tableData"
                 checktype="检查"
                 v-model:show="checkDialog.show"
                 v-if="checkDialog.show"
      ></CheckList>
    </el-dialog>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import DockerTitle from '@/components/doctor/title'
import { RegisterStore } from '@/stores/counter'
import CheckList from './checkList'
import { ElMessage } from 'element-plus'
import { post } from '@/util/axios'
const wytable = ref()
const wyform = reactive({
  registerId: '',
  medicalTechnologyId: null,
  checkInfo: '',
  checkPosition: '',
  checkRemark: ''
})
const registerStore = RegisterStore()
const registRecord = registerStore.get()
wyform.registerId = registRecord.value.id
const tableData = ref([])
const checkDialog = reactive({
  show: false
})
function delCheck () {
  const rows = wytable.value.getSelectionRows()
  if (rows.length === 0) {
    ElMessage.error('请选择要删除的检查项')
  } else {
    tableData.value.splice(0, 1)
  }
}
function save () {
  wyform.medicalTechnologyId = tableData.value[0].id
  post('/checkRequest/add', wyform, content => {
    console.dir(content)
  })
}
</script>

<style scoped lang="scss">
.el-form {
  margin-top: 30px;
  width: 1000px;
  .el-form-item  {
    margin-bottom: 1px;
    background-color: #FAFAFA;
  }
}
</style>
